package com.nightcolor.im;

import com.nightcolor.im.framework.BaseActivity;
import com.nightcolor.im.framework.Utils;
import com.nightcolor.im.view.HorizontalListView;
import com.nightcolor.im.R;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.ViewSwitcher;

public class HorizontalLvTest extends BaseActivity implements View.OnClickListener {

    private HorizontalListView mHrListView;
    private ListView mListView;
    private ViewSwitcher viewSw;
    private TextView tvEdit;
    private EditText etUserStatus;
    private TextView tvUserStatus;

    private static final String EDIT = "edit";
    private static final String SAVE = "save";

    public class MyAdapter extends BaseAdapter {

        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = null;
            if (convertView == null) {
                v = getLayoutInflater().inflate(
                        R.layout.homepage_user_visitor_item, null);
                ImageView iv = (ImageView) v
                        .findViewById(R.id.iv_user_visitor_avator);
                iv.setImageResource(R.drawable.ic_launcher);
                TextView tv = (TextView) v
                        .findViewById(R.id.tv_user_visitor_name);
                tv.setText("big_girl");
            } else {
                v = convertView;
            }
            return v;
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.night_color_user_homepage);
        mHrListView = (HorizontalListView) this
                .findViewById(R.id.hr_lv_user_visitor);
        mListView = (ListView) this.findViewById(R.id.lv_user_recent_actions);
        MyAdapter adapter = new MyAdapter();
        mHrListView.setAdapter(adapter);
        MyAdapter adapter1 = new MyAdapter();
        mListView.setAdapter(adapter1);

        viewSw = (ViewSwitcher) this.findViewById(R.id.view_switch_user_status);
        viewSw.setDisplayedChild(0);
        tvEdit = (TextView) this.findViewById(R.id.bt_edit_user_status);
        tvEdit.setTag(EDIT);
        tvEdit.setOnClickListener(this);
        
        etUserStatus= (EditText)this.findViewById(R.id.et_user_status);
        tvUserStatus = ( TextView)this.findViewById(R.id.tv_user_status);
    }

    @Override
	protected View genContentView() {
		return Utils.inflateLayout(
				this, R.layout.night_color_user_homepage, null);
	}



	@Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onStart() {
        super.onStart();
    }

    @Override
    public void onClick(View v) {
        int viewId = v.getId();
        switch (viewId) {
        case R.id.bt_edit_user_status:
            if (EDIT.equalsIgnoreCase((String) v.getTag())) {
                viewSw.showNext();
                tvEdit.setText("����");
                tvEdit.setTag(SAVE);
                final String status = tvUserStatus.getText().toString().trim();
                if (!TextUtils.isEmpty(status)) {
                    etUserStatus.setText(status);
                    etUserStatus.setSelection(status.length());
                }
            }else if(SAVE.equalsIgnoreCase((String) v.getTag())){
                viewSw.showPrevious();
                tvEdit.setText("�༭");
                tvEdit.setTag(EDIT);
                tvUserStatus.setText(etUserStatus.getText().toString().trim());
            }else{
                
            }
            break;
        default:
            break;
        }
    }

	@Override
	public void onSlideChange(boolean isMenuOpen) {
	}
    
}
